﻿
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Snowy.Data;
using Snowy.Data.PostgreSQL;
using System;
using System.Linq;
namespace Microsoft.Extensions.DependencyInjection
{
    public static class SnowyDataBuilderExtensions
    {
        public static void ConfigureNpgsql(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder)
        {
            services.AddEntityFrameworkNpgsql();
            services.AddSingleton<IDataBaseModelBuilderOptions>(c => new NpgsqlModelBuilderOptions());
            services.AddDbContextPool<ApplicationDbContext>(builder =>
            {
                builder.UseNpgsql(connectionString, s => s.MigrationsAssembly("Snowy.Data.PostgreSQL"));
                builder.UseInternalServiceProvider(services.BuildServiceProvider());
            }
     , poolSize);
            checksBuilder.AddNpgSql(connectionString, name: "Snowy.Data.PostgreSQL");
        }

    }
}
